package top.toptimus.dto.measure;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 量体值配置项目，带父子项目
 */
@NoArgsConstructor
@Data
public class MeasureItemConfigDTO {
    //  存储
    private String id;
    private String parentId;
    private String code;
    private String ITEM_CD;
    private String ITEM_VALUE;
    private String ITEM_NAME_CN;
    private boolean isFIT_VALUE; // 人尺寸值
    private boolean isGarmentSize;  //    成衣尺寸
    private boolean isHalf; //  是否有1/2
    private int index;

    public MeasureDTO build() {
        return new MeasureDTO(
                this.id
                , this.parentId
                , this.code
                , this.ITEM_CD
                , this.ITEM_VALUE
                , this.ITEM_NAME_CN
                , this.isFIT_VALUE
                , this.isGarmentSize
                , this.isHalf
                , this.index
        );
    }

    public MeasureItemConfigDTO(MeasureDTO measureDTO) {
        //  父级
        this.id = measureDTO.getCode();
        if (measureDTO.getCode().contains(".")) {
            //  子项目
            this.parentId = measureDTO.getCode().substring(0, measureDTO.getCode().indexOf("."));
        }

        this.code = measureDTO.getCode();
        this.ITEM_CD = measureDTO.getITEM_CD();
        this.ITEM_VALUE = measureDTO.getITEM_VALUE();
        this.ITEM_NAME_CN = measureDTO.getITEM_NAME_CN();
        this.isFIT_VALUE = measureDTO.isFIT_VALUE();
        this.isGarmentSize = measureDTO.isGarmentSize();
        this.isHalf = measureDTO.isHalf();
        this.index = measureDTO.getIndex();
    }

    public MeasureItemConfigDTO(
            String ITEM_CD,
            String ITEM_VALUE,
            String ITEM_NAME_CN,
            String id,
            int index) {
        this.id = id;
        this.ITEM_CD = ITEM_CD;
        this.ITEM_VALUE = ITEM_VALUE;
        this.ITEM_NAME_CN = ITEM_NAME_CN;
        this.index = index;
    }
}
